import { dingConfig } from 'dingtalk-app';
import * as fs from 'fs';
import * as Koa from 'koa';
import evn from './config/env';
import dTalkApi from './core/dTalkApi';
import finalHandler from './lib/middlewares/finalHandler';
import backupService from './services/backupService';
const bodyParser = require('koa-bodyparser');
const _logger = require('koa-logger');
const views = require('koa-views');
const convert = require('koa-convert');
const serve = require('koa-static');
let log4js = require('koa-log4');
const app = new Koa();

app.use(finalHandler());
app.use(views(`${__dirname}/views`, {
    map: {
        html: 'nunjucks'
    }
}));
app.use(_logger());
app.use(bodyParser());
app.keys = ['some secret hurr'];
app.use(serve(__dirname + '/public'));
dingConfig.init(app, evn, [/^\/api\/*/])
let files = fs.readdirSync('./routers')
files.map(item => {
    console.log(`./routers/${item.substr(0, item.indexOf('.'))}`);
    const router: any = require(`./routers/${item.substr(0, item.indexOf('.'))}`)
    app.use(router.default.routes())
})

   


export default app;

